# -*- coding: utf-8 -*-
# @Time    : 2022/7/28 14:21
# @Author  : Yanfeng
# @Email   : sxyanfeng2014@163.com
# @File    : functions_control.py
# @Software: PyCharm

import allure
import pytest
from selenium import webdriver
from selenium.webdriver.common.by import By

from Common.dir_config import ConfigHandler
from Common.yaml_func import Yaml_func
from util.readFileUtils.yamlControl import GetYamlData


@pytest.fixture
def init_driver():  #打开浏览器，访问网址
    """
    前置：打开浏览器，访问网址
    后置：退出浏览器
    :return:
    """
    login_url = GetYamlData().get_yaml_data()["host"]
    driver = webdriver.Edge(executable_path=ConfigHandler.driver_dir)
    with allure.step("访问{}，最大化".format(login_url)):
        driver.get(login_url)
        driver.maximize_window()
    yield driver
    with allure.step("关闭浏览器"):
        driver.quit()


@pytest.fixture
def init_login(init_driver):
    with allure.step("登录"):
        yf = Yaml_func(init_driver)
        code = yf.get_code("captchaImage")
        yf.input_text((By.ID,'TextAdminName'),"Admin63770","登录页面-输入用户名")
        yf.input_text((By.ID,'TextPassword'),"huxiaolong888","登录页面-输入密码")
        yf.input_text((By.ID,'txtValidate'),code,"登录页面-输入验证码")
        yf.click_element((By.ID,'submit'),"登录页面，点击登录按钮")
    yield init_driver








